package com.example.demo.service.factory;

import com.example.demo.service.HelloService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * 类描述：HelloServiceFactoryBean
 * @author lff
 * @date 2021/12/17 9:07
 *
 */
@Primary
@Component
public class HelloServiceFactoryBean implements FactoryBean<HelloService>, ApplicationContextAware {
    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    @Override
    public HelloService getObject() throws Exception {
        return context.getBean("crm6HelloServiceImpl", HelloService.class);
    }


    @Override
    public Class<?> getObjectType() {
        return HelloService.class;
    }
}
